#!/usr/bin/python
# -*- coding: utf-8 -*-

##
 # Copyright 2009 Caio Souza
 # This file is part of Rpyg.
 #
 # Rpyg is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # Rpyg is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with Rpyg. If not, see <http://www.gnu.org/licenses/>.
 ##

'''Módulo dos quadros das imagens.'''

import pygame

from rpyg.Blitable import Blitable
from rpyg.Layer import Layer

class Frame (Blitable):
    '''Quadro de uma imagem.
    
    Uma imagem pode possuir diversos quadros, cada um com o seu intervalo
    de exposição. Um quadro contem camadas que são sobrespostas para
    formar uma única superfície.
    '''
    
    def __init__ (self, layers, time = 0):
        '''Cria um quadro a partir da lista de camadas e do tempo de exposição.'''
        Blitable.__init__ (self)
        
        if isinstance (layers, Layer): layers = [layers]
        
        self._time = time
        rect = layers[0].getSurface ().get_rect ()
        self._surface = pygame.Surface ((rect.w, rect.h), pygame.SRCALPHA).convert_alpha ()
        for layer in layers:
            self._surface.blit (layer.getSurface (), (0, 0))
    
    def getTime (self):
        '''Retorna o tempo de exposição do quadro.'''
        return self._time